package org.xx.armory.swing.builders;

import org.xx.armory.objectparser.LineInfo;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import static org.apache.commons.lang3.StringUtils.trimToEmpty;

/**
 * 下拉框模型。
 */
public class DropDownModel
        extends AbstractComponentModel
        implements ComponentModel {
    private final boolean includeAll;
    private final boolean includeNone;
    private final int size;
    private final String optionsName;
    private final boolean required;
    private final List<OptionModel> options;

    /**
     * 构造下拉框模型对象。
     *
     * @param lineInfo
     *         源文件中的位置信息。
     * @param name
     *         组件的名字。
     * @param includeAll
     *         是否包含{@literal 全部}选项。
     * @param includeNone
     *         是否包含{@literal 无}选项。
     * @param required
     *         是否必选，即不能选中值为空的选项。
     * @param optionsName
     *         选项组的名字。
     * @param options
     *         可选择的选项列表。
     */
    protected DropDownModel(
            LineInfo lineInfo,
            String name,
            boolean visible,
            boolean includeAll,
            boolean includeNone,
            boolean simple,
            int size,
            boolean required,
            String optionsName,
            List<? extends OptionModel> options
    ) {
        super(lineInfo, name, visible);

        this.includeAll = includeAll;
        this.includeNone = includeNone;
        this.size = size;
        this.required = required;
        this.optionsName = trimToEmpty(optionsName);
        this.options = options != null ? new ArrayList<>(options) : Collections.emptyList();
    }

    public boolean isIncludeAll() {
        return this.includeAll;
    }

    public boolean isIncludeNone() {
        return this.includeNone;
    }

    public int getSize() {
        return this.size;
    }

    public boolean isRequired() {
        return this.required;
    }

    public String getOptionsName() {
        return this.optionsName;
    }

    public List<OptionModel> getOptions() {
        return this.options;
    }
}
